﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BL;
using DA;
using Entities;


namespace ERP
{
    public partial class ItemForm : BaseERPPage
    {
        OrderItemManager orderItemManager = new OrderItemManager();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string OrderItemId = Request.QueryString.Get("OrderItemId");
                if (!string.IsNullOrEmpty(OrderItemId))
                {
                    ERP_OrderItems item = orderItemManager.GetItem(int.Parse(OrderItemId));
                    txtName.Text = item.OrderItemName;
                }
            }
        }

        protected void btn_click(object sender, EventArgs e)
        {
            int OrderItemId;
            if (int.TryParse(Request.QueryString.Get("OrderItemId"), out OrderItemId))
            {
               ERP_OrderItems OrderItemToUpdate = orderItemManager.GetItem(OrderItemId);
               OrderItemToUpdate.OrderItemName = txtName.Text;
               if (orderItemManager.UpdateOrderItem(OrderItemToUpdate))
               {
                   Response.Redirect("OrderForm.aspx", true);
               }
            }

            else
            {//new order
                ERP_OrderItems OrderItem = new ERP_OrderItems();
                OrderItem.OrderItemName = txtName.Text;
                if (orderItemManager.AddOrderItem(OrderItem))
                {
                    Response.Redirect("OrderForm.aspx", true);
                }
            }
        }

    }
}